<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('核心基金经理')" prop="coreFundManager">
            <el-input v-model="form.coreFundManager" :placeholder="$t('核心基金经理')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投研团队')" prop="investmentResearchTeam">
            <el-input v-model="form.investmentResearchTeam" type="textarea" :placeholder="$t('投研团队')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('激励机制')" prop="excitationMechanism">
            <el-input v-model="form.excitationMechanism" type="textarea" :placeholder="$t('激励机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投研能力提升')" prop="investmentImprovement">
            <el-input v-model="form.investmentImprovement" type="textarea" :placeholder="$t('投研能力提升')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('团队稳定性')" prop="teamStability">
            <el-input v-model="form.teamStability" type="textarea" :placeholder="$t('团队稳定性')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 附件列表 -->
      <FileTable :list.sync="form.fileList" data-type="gp_security_team" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="gpSecurity:team" />
    </div>
  </div>
</template>

<script>
    import { saveGpSecurityTeam, getGpSecurityTeam } from '@/api/deal/gpSecurity/team/gpSecurityTeam'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  coreFundManager: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  investmentResearchTeam: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  excitationMechanism: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  investmentImprovement: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  teamStability: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                },
                // 是否隐藏其它按钮
                otherBtnHide: false
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getGpSecurityTeam(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                      this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    gpSecurityId: this.$route.query.id,
                    coreFundManager: undefined,
                    investmentResearchTeam: undefined,
                    excitationMechanism: undefined,
                    investmentImprovement: undefined,
                    teamStability: undefined,
                    remark: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveGpSecurityTeam(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           }
        }
    }
</script>
